﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Jn698._45GWTool.Convers
{
    public class StringToParityConver : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string str = "无校验";
            if (value == null) return str;
            
            switch (value)
            {   
                
                case Parity.Odd:
                    str = "奇校验";
                    break;
                case Parity.Even:
                    str = "偶校验";
                    break;
                
                case Parity.None:
                default:
                    str = "无校验";
                    break;
            }
            return str;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return Parity.None;
            if (value.Equals("奇校验"))
            {
                return Parity.Odd;
            }
            else if (value.Equals("偶校验"))
            {
                return Parity.Even;
            }
            return Parity.None;
        }
    }
}
